<?php

function show_tab_news() {
    require ('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_news . " ORDER BY id desc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des news : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucune news n'a encore &eacute;t&eacute; post&eacute;e.
        </div>
        <br />
        <?php
        add_news();
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutes les news\">";
        echo "<colgroup>" . "\n\t\t";
        for ($col = 1; $col <= 7; $col++) {
            echo "<col width=\"90px\">";
            if ($col < 7) {
                echo "\n\t\t";
            } else if ($col == 7) {
                echo "\n\t";
            }
        }
        echo "</colgroup>";
        echo "<thead><th scope=\"col\">Titre</th><th scope=\"col\">Auteur</th><th scope=\"col\">Texte</th><th scope=\"col\">Date</th><th colspan=\"2\" scope=\"col\"><form method=\"post\" //action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"submit\" name=\"add\" value=\"Ajouter une news\" class=\"btn\"></form></thead>";
        while ($line = mysql_fetch_assoc($result)) {
            $date_usa = $line['date'];
            $date = substr($date_usa, 8, 10) . "/" . substr(substr($date_usa, 5, 7), 0, 2) . "/" . substr($date_usa, 0, 4);
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $line ['title'];
            echo "</td><td>";
            echo $line ['author'];
            echo "</td><td>";
            echo substr($line ['content'], 0, 20);
            echo "</td><td>";
            echo $date;
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $line ['id'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_news' value='Supprimer' alt='Supprimer' title='Supprimer'><br /></form></td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"edit_id\" value=\"" . $line ['id'] . "\"><input type='image' src=\"../images/icone/edit_little.png\" name='edit_news' value='Editer' alt='Editer' title='Editer'><br /></form>";
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function add_news() {
    require('./connexion.php');
    $author = @$_SESSION['login'];
    $jour = date('j');
    if ($jour < 9) {
        $jour = "0" . date('j');
    }
    $mois = date('m');

    $date = $jour . "/" . date('m') . "/" . date('Y');
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Ajouter une news">
            <thead>
            <th colspan="2">Ajouter une news</th>
            </thead>
            <tbody>
                <tr>
                    <td>Titre :</td><td><input type="text" name="title" /><input type="hidden" name="author" value="<?php echo $author; ?>" /></td>
                </tr>
                <?php show_bbcode_box_admin('news'); ?>
                <tr>
                    <td>News :</td><td><textarea cols="50" rows="20" name="news" id="news"></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
    <!--                    <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=preview&title=<?php echo $_POST['title']; ?>&news=<?php echo $_POST['news']; ?>" class="btn">Pr&eacute;visualiser</a></td>--><td colspan="2"><input type="submit" name="save_news" value="Poster" class="btn" /></form></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function preview_news($title, $news) {
    require('./connexion.php');
    $author = $_SESSION['author'];
    $jour = date('j');
    if ($jour < 9) {
        $jour = "0" . date('j');
    }
    $mois = date('m');

    $date = $jour . "/" . date('m') . "/" . date('Y');
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Ajouter une news">
            <thead>
            <th colspan="2">Ajouter une news</th>
            </thead>
            <tbody>
                <tr>
                    <td>Titre :</td><td><input type="text" name="title" value="<?php echo $title; ?>" /><input type="hidden" name="author" value="<?php echo $_SESSION['login']; ?>" /></td>
                </tr>
                <tr>
                    <td>News :</td><td><textarea cols="50" rows="20" name="news"><?php echo $news; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=preview&title=<?php echo $_POST['title']; ?>&news=<?php echo $_POST['news']; ?>" class="btn">Pr&eacute;visualiser</a></td><td><input type="submit" name="save_news" value="Poster" class="btn" /></form></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function edit_news() {
    require('./connexion.php');
    $id = $_POST['edit_id'];
    $query = "SELECT * FROM " . $database . "." . $tb_news . " WHERE id = '$id'";
    $result = mysql_query($query) OR DIE(mysql_error());
    $modif = mysql_fetch_assoc($result);
    $title = $modif['title'];
    $author = $modif['author'];
    $date_usa = $modif['date'];
    $news = $modif['content'];

    $date = substr($date_usa, 8, 10) . "/" . substr(substr($date_usa, 5, 7), 0, 2) . "/" . substr($date_usa, 0, 4);
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Editer une news">
            <thead>
            <th colspan="2">Editer une news</th>
            </thead>
            <tbody>
                <tr>
                    <td>Titre :</td><td><input type="text" name="title_edited" value="<?php echo $title; ?>" /><input type="hidden" name="author_edited" value="<?php echo $author; ?>" /><input type="hidden" name="date_edited" value="<?php echo $date; ?>" /></td>
                </tr>
                <?php show_bbcode_box_admin('news_edited'); ?>
                <tr>
                    <td>News :</td><td><textarea cols="50" rows="20" name="news_edited" id="news_edited"><?php echo $news; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id_edited" value="<?php echo $id; ?>" /></td><td><input type="submit" name="save_edit_news" value="&Eacute;diter" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function show_tab_user() {
    require ('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_utilisateurs . " ORDER BY privilege asc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des utilisateurs : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucun utilisateur n'a encore &eacute;t&eacute; cr&eacute;&eacute;.
        </div>
        <br />
        <a href="./accueil.php?action=back" class="btn">Retourner au Panneau d'administration</a> <br />
        <?php
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutles utilisateurs\">";
        echo "<colgroup>" . "\n\t\t";
        if ($_SESSION['privilege'] == "admin") { // Affichage conditionnel : si et seulement si l'utilisateur est connect&eacute; avec le privilege utilisateur simple
            for ($col = 1; $col <= 8; $col++) {
                echo "<col width=\"90px\">";
                if ($col < 8) {
                    echo "\n\t\t";
                } else if ($col == 8) {
                    echo "\n\t";
                }
            }
        } else {
            for ($col = 1; $col <= 6; $col++) {
                echo "<col width=\"90px\">";
                if ($col < 6) {
                    echo "\n\t\t";
                } else if ($col == 6) {
                    echo "\n\t";
                }
            }
        }

        echo "</colgroup>";
        if ($_SESSION['privilege'] == "admin") { // Affichage conditionnel : si et seulement si l'utilisateur est connect&eacute; avec le privilege utilisateur simple
            echo "<thead><th scope=\"col\">Pseudo</th><th scope=\"col\">Privil&egrave;ge</th><th scope=\"col\">Pr&eacute;nom</th><th scope=\"col\">Nom</th><th scope=\"col\">Date d'inscription</th><th scope=\"col\">E-mail</th><th scope=\"col\">Skype</th><th colspan=\"2\" scope=\"col\"><form method=\"post\" //action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"submit\" name=\"add\" value=\"Ajouter un utilisateur\" class=\"btn\"></form></th></thead>";
        } else {
            echo "<thead><th scope=\"col\">Pseudo</th><th scope=\"col\">Privil&egrave;ge</th><th scope=\"col\">Pr&eacute;nom</th><th scope=\"col\">Nom</th><th scope=\"col\">Date d'inscription</th><th scope=\"col\">E-mail</th><th scope=\"col\">Skype</th></thead>";
        }
        while ($line = mysql_fetch_assoc($result)) {
            $date_usa = $line['date_inscription'];
            $date = substr($date_usa, 8, 10) . "/" . substr(substr($date_usa, 5, 7), 0, 2) . "/" . substr($date_usa, 0, 4);
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo utf8_encode($line ['login']);
            echo "</td><td>";
            echo $line['privilege'];
            echo "</td><td>";
            echo utf8_encode($line ['prenom']);
            echo "</td><td>";
            echo utf8_encode($line ['nom']);
            echo "</td><td>";
            echo $date;
            echo "</td><td>";
            echo $line ['email'];
            echo "</td><td>";
            echo $line ['skype'];
            echo "</td><td>";
            if ($_SESSION['privilege'] == "admin") { // Affichage conditionnel : si et seulement si l'utilisateur est connect&eacute; avec le privilege utilisateur simple
                echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $line ['id_user'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_user' value='Supprimer' alt='Supprimer' title='Supprimer' id=\"btn_opt\"><br /></form></td><td>";
                echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"edit_id\" value=\"" . $line ['id_user'] . "\"><input type='image' src=\"../images/icone/edit_little.png\" name='edit_user' value='Editer' alt='Editer' title='Editer' id=\"btn_opt\"><br /></form>";
                echo "</td></tr></tbody>";
            } else {
                echo "</td></tr></tbody>";
            }
        }
        echo "</table>";
    }
}

function add_user() {
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Ajouter un utilisateur">
            <thead>
            <th colspan="2">Ajouter un utilisateur</th>
            </thead>
            <tbody>
                <tr>
                    <td>Pseudo :</td><td><input type="text" name="login" /></td>
                </tr>
                <tr>
                    <td>Mot de passe :</td><td><input type="password" name="pass" /></td>
                </tr>
                <tr>
                    <td>R&eacute;p&eacute;ter le mot de passe :</td><td><input type="password" name="pass2" /></td>
                </tr>
                <tr>
                    <td>Privil&egrave;ge :</td>
                    <td>
                        <select name="privilege" id="privilege">
                            <option value="user">Utilisateur</option>
                            <option value="admin">Administrateur</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>E-mail :</td><td><input type="text" name="email" /></td>
                </tr>
                <tr>
                    <td>Pr&eacute;nom :</td><td><input type="text" name="prenom" /></td>
                </tr>
                <tr>
                    <td>Nom :</td><td><input type="text" name="nom" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td><input type="submit" name="save_user" value="Enregistrer" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function edit_user() {
    require('./connexion.php');
    $id = $_POST['edit_id'];
    $query = "SELECT * FROM " . $database . "." . $tb_utilisateurs . " WHERE id_user='$id'";
    $result = mysql_query($query) OR DIE(mysql_error());
    $modif = mysql_fetch_assoc($result);
    $login = $modif['login'];
    $pass = $modif['pass'];
    $pass2 = $modif['pass'];
    $nom = $modif['nom'];
    $prenom = $modif['prenom'];
    $email = $modif['email'];
    $privilege = $modif['privilege'];
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Editer un utilisateur">
            <thead>
            <th colspan="2">Editer un utilisateur</th>
            </thead>
            <tbody>
                <tr>
                    <td>Pseudo :</td><td><input type="text" name="login_edited" value="<?php echo $login; ?>" /></td>
                </tr>
                <tr>
                    <td>Mot de passe :</td><td><input type="password" name="pass_edited" value="<?php echo $pass; ?>" /></td>
                </tr>
                <tr>
                    <td>R&eacute;p&eacute;ter le mot de passe :</td><td><input type="password" name="pass2_edited" value="<?php echo $pass2; ?>" /></td>
                </tr>
                <tr>
                    <td>Privil&egrave;ge :</td>
                    <td>
                        <select name="privilege_edited" id="privilege">
                            <option value="user">Utilisateur</option>
                            <option value="admin">Administrateur</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>E-mail :</td><td><input type="text" name="email_edited" value="<?php echo $email; ?>" /></td>
                </tr>
                <tr>
                    <td>Pr&eacute;nom :</td><td><input type="text" name="prenom_edited" value="<?php echo $prenom; ?>" /></td>
                </tr>
                <tr>
                    <td>Nom :</td><td><input type="text" name="nom_edited" value="<?php echo $nom; ?>" /></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id_edited" value="<?php echo $id; ?>" /></td><td><input type="submit" name="save_edit_user" value="&Eacute;diter" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function show_tab_comment() {
    require ('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_comment . " ORDER BY id_news_com desc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des commentaires : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucun commentaire n'a encore &eacute;t&eacute; post&eacute;.
        </div>
        <br />
        <a href="./accueil.php?action=back" class="btn">Retourner au Panneau d'administration</a> <br />
        <?php
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Tout les commentaires\">";
        echo "<colgroup>" . "\n\t\t";
        for ($col = 1; $col <= 54; $col++) {
            echo "<col width=\"90px\">";
            if ($col < 4) {
                echo "\n\t\t";
            } else if ($col == 4) {
                echo "\n\t";
            }
        }
        echo "</colgroup>";
        echo "<thead><th scope=\"col\">Auteur du<br />Commentaire</th><th scope=\"col\" width=\"150px\">Commentaire</th><th scope=\"col\">Date d'ajout</th><th scope=\"col\" colspan=\"2\">Options</thead>";
        while ($line = mysql_fetch_assoc($result)) {
            $date_usa = $line['date_com'];
            $date = substr($date_usa, 8, 10) . "/" . substr(substr($date_usa, 5, 7), 0, 2) . "/" . substr($date_usa, 0, 4);
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $line ['author_com'];
            echo "</td><td>";
            echo substr($line ['comment_com'], 0, 40);
            echo "</td><td>";
            echo $date;
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?view_comment=" . $line ['id_com'] . "\" ><input type=\"hidden\" name=\"view_id\" value=\"" . $line ['id_com'] . "\"><input type='image' src=\"../images/icone/view_little.png\" name='view_comment' value='Lire le commentaire' alt='lire le commentaire' title='Lire le commentaire'></form></td>";
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $line ['id_com'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_comment' value='Supprimer' alt='Supprimer' title='Supprimer'></form></tr></tbody>";
        }
        echo "</table>";
    }
}

function show_tab_mp() {
    require('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_mp . " ORDER BY id_mp desc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des utilisateurs : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucun message priv&eacute; n'a encore &eacute;t&eacute; envoy&eacute;.
        </div>
        <?php
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Tout les mp\">";
        echo "<thead><th scope=\"col\">Exp&eacute;diteur</th><th scope=\"col\">R&eacute;ceptionneur</th><th scope=\"col\">Sujet</th><th scope=\"col\">Date</th><th scope=\"col\">Heure</th><th scope=\"col\" colspan=\"2\">Options</th></thead>";
        while ($mp = mysql_fetch_assoc($result)) {
            $date_usa = $mp['date_mp'];
            $date_mp = substr($date_usa, 8, 10) . "/" . substr(substr($date_usa, 5, 7), 0, 2) . "/" . substr($date_usa, 0, 4);
            $heure_usa = $mp['heure_mp'];
            $heure_mp = substr($heure_usa, 0, 2) . "h" . substr($heure_usa, 3, 5);
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo "<a href=\"../user.php?user=" . $mp ['from_mp'] . "\" title=\"Voir le profil de " . $mp ['from_mp'] . "\" class=\"mainlinks lightblue\">" . $mp ['from_mp'] . "</a>";
            echo "</td><td>";
            echo "<a href=\"../user.php?user=" . $mp ['to_mp'] . "\" title=\"Voir le profil de " . $mp ['to_mp'] . "\" class=\"mainlinks lightblue\">" . $mp ['to_mp'] . "</a>";
            echo "</td><td>";
            echo $mp ['title_mp'];
            echo "</td><td>";
            echo $date_mp;
            echo "</td><td>";
            echo $heure_mp;
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"view_id\" value=\"" . $mp ['id_mp'] . "\"><input type='image' src=\"../images/icone/view_little.png\" name='view_mp' value='Voir la conversation' alt='Voir la conversation' title='Voir la conversation'><br /></form></td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $mp ['id_mp'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_mp' value='Supprimer' alt='Supprimer' title='Supprimer'><br /></form>";
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function show_tab_faq() {
    require('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_faq . " ORDER BY id_faq asc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des questions-r&eacute;ponses de la F.A.Q. : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucune question n'a encore &eacute;t&eacute; r&eacute;dig&eacute;e.
        </div>
        <br />
        <br />
        <?php
        add_faq();
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutes les users\">";
        echo "<thead><th scope=\"col\">Questions</th><th scope=\"col\">R&eacute;ponses</th><th scope=\"col\" colspan=\"2\"><form method=\"post\" //action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"submit\" name=\"add\" value=\"Ajouter une question\" class=\"btn\"></form></th></thead>";
        while ($faq = mysql_fetch_assoc($result)) {
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $faq['question_faq'] . "</td><td>";
            echo $faq['reponse_faq'];
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"edit_id\" value=\"" . $faq ['id_faq'] . "\"><input type='image' src=\"../images/icone/edit_little.png\" name='edit_faq' value='&Eacute;diter' alt='&Eacute;diter' title='&Eacute;diter'><br /></form></td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $faq ['id_faq'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_faq' value='Supprimer' alt='Supprimer' title='Supprimer'><br /></form>";
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function add_faq() {
    require('./connexion.php');
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellspacing="2" id="pattern-style-b" summary="Ajouter une question">
            <thead>
            <th colspan="2">Ajouter une question</th>
            </thead>
            <tbody>
                <tr>
                    <td>Question :</td><td><input type="text" name="question" /></td>
                </tr>
                <?php show_bbcode_box_admin('reponse'); ?>
                <tr>
                    <td>R&eacute;ponse :</td><td><textarea cols="50" rows="10" name="reponse" id="reponse"></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="save_faq" value="Poster" class="btn" /></form></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function edit_faq() {
    require('./connexion.php');
    $id = $_POST['edit_id'];
    $query = "SELECT * FROM " . $database . "." . $tb_faq . " WHERE id_faq = '$id'";
    $result = mysql_query($query) OR DIE(mysql_error());
    $modif = mysql_fetch_assoc($result);
    $question = $modif['question_faq'];
    $reponse = $modif['reponse_faq'];
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Editer une question">
            <thead>
            <th colspan="2">Editer une question</th>
            </thead>
            <tbody>
                <tr>
                    <td>Question :</td><td><input type="text" name="question_edited" value="<?php echo $question; ?>" /></td>
                </tr>
                <?php show_bbcode_box_admin('reponse_edited'); ?>
                <tr>
                    <td>R&eacute;ponse :</td><td><textarea name="reponse_edited" id="reponse_edited" cols="50" rows="15"><?php echo $reponse; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id_edited" value="<?php echo $id; ?>" /></td><td><input type="submit" name="save_edit_faq" value="&Eacute;diter" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function show_tab_iconomy() {
    require('./connexion.php');
    $query = "SELECT * FROM " . $database . "." . $tb_iconomy . "";
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des comptes iConomy : " . mysql_error());
    $line = mysql_fetch_assoc($result);
    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucun compte iConomy n'a encore &eacute;t&eacute; cr&eacute;&eacute;.
        </div>
        <br />
        <br />
        <?php
    } else {
        ?>
        <fieldset class="fieldset">
            <legend>Gestion des comptes</legend>
            <br />
            <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                <table>
                    <tr>
                        <td>Action :</td>
                        <td>
                            <select name="action">
                                <option>Cr&eacute;diter</option>
                                <option>D&eacute;biter</option>
                                <option>Consulter</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Compte de :</td>
                        <td>
                            <select name="to">
                                <?php
                                while ($user = mysql_fetch_assoc($result)) {
                                    ?>
                                    <option value="<?php echo $user['username']; ?>"><?php echo $user['username']; ?></option>
                                    <?php
                                }
                                ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Montant :</td>
                        <td><input type="text" name="montant" value="0" /></td>
                    </tr>
                </table>
                <br />
                <input type="submit" value="Soumettre" name="todo" class="btn" />&nbsp;<a href="./iconomy.php?action=showall" class="btn">Voir toute l'&eacute;conomie</a><br />
                <br />
            </form>
        </fieldset>
        <?php
    }
}

function show_tab_all_iconomy() {
    require('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_iconomy . " ORDER BY balance asc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection de toute l'&eacute;nomie : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucune compte iConomy n'existe.
        </div>
        <br />
        <br />
        <?php
        add_faq();
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutes les users\">";
        echo "<thead><th scope=\"col\">Pseudo</th><th scope=\"col\">Solde</th></thead>";
        while ($ico = mysql_fetch_assoc($result)) {
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $ico['username'] . "</td><td>";
            echo $ico['balance'];
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function show_tab_team() {
    require ('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_team . " ORDER BY id_team desc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection de la team : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucune pr&eacute;sentation n'a encore &eacute;t&eacute; post&eacute;e.
        </div>
        <br />
        <?php
        add_team();
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutes la team\">";
        echo "<colgroup>" . "\n\t\t";
        for ($col = 1; $col <= 7; $col++) {
            echo "<col width=\"90px\">";
            if ($col < 7) {
                echo "\n\t\t";
            } else if ($col == 7) {
                echo "\n\t";
            }
        }
        echo "</colgroup>";
        echo "<thead><th scope=\"col\">Titre</th><th scope=\"col\">Auteur</th><th scope=\"col\">Texte</th><th scope=\"col\">Date</th><th colspan=\"2\" scope=\"col\"><form method=\"post\" //action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"submit\" name=\"add\" value=\"Ajouter une pr&eacute;sentation\" class=\"btn\"></form></thead>";
        while ($line = mysql_fetch_assoc($result)) {
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $line ['pseudo_team'];
            echo "</td><td>";
            echo $line ['rang_team'];
            echo "</td><td>";
            echo $line ['fonction_team'];
            echo "</td><td>";
            echo $line['description_team'];
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $line ['id_team'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_team' value='Supprimer' alt='Supprimer' title='Supprimer'><br /></form></td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"edit_id\" value=\"" . $line ['id_team'] . "\"><input type='image' src=\"../images/icone/edit_little.png\" name='edit_team' value='Editer' alt='Editer' title='Editer'><br /></form>";
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function add_team() {
    require('./connexion.php');
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Ajouter une pr&eacute;sentation">
            <thead>
            <th colspan="2">Ajouter une pr&eacute;sentation</th>
            </thead>
            <tbody>
                <tr>
                    <td>Pseudo :</td><td><input type="text" name="pseudo" /> <i class="px10">(Son pseudo en minuscule)</i></td>
                </tr>
                <tr>
                    <td>Rang :</td>
                    <td>
                        <select name="rang">
                            <option>admin</option>
                            <option>modo</option>
                        </select>
                        <i class="px10">(Son rang sur le serveur)</i>
                    </td>
                </tr>
                <tr>
                    <td>Fonction :</td><td><input type="text" name="fonction" /> <i class="px10">(Description de ce qu'il fait)</i></td>
                </tr>
                <?php show_bbcode_box_admin('description'); ?>
                <tr>
                    <td>Description :</td><td><textarea name="description" id="description" cols="40" rows="4">Son &acirc;ge, son m&eacute;tier, etc...</textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="save_team" value="Ajouter" class="btn" /></form></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function edit_team() {
    require('./connexion.php');
    $id = $_POST['edit_id'];
    $query = "SELECT * FROM " . $database . "." . $tb_team . " WHERE id_team = '$id'";
    $result = mysql_query($query) OR DIE(mysql_error());
    $modif = mysql_fetch_assoc($result);
    $pseudo = $modif['pseudo_team'];
    $fonction = $modif['fonction_team'];
    $description = $modif['description_team'];
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Editer une news">
            <thead>
            <th colspan="2">Editer une news</th>
            </thead>
            <tbody>
                <tr>
                    <td>Pseudo :</td><td><input type="text" name="pseudo_edited" value="<?php echo $pseudo; ?>"/> <i class="px10">(Son pseudo en minuscule)</i></td>
                </tr>
                <tr>
                    <td>Rang :</td>
                    <td>
                        <select name="rang_edited">
                            <option>admin</option>
                            <option>modo</option>
                        </select>
                        <i class="px10">(Son rang sur le serveur)</i>
                    </td>
                </tr>
                <tr>
                    <td>Fonction :</td><td><input type="text" name="fonction_edited" value="<?php echo $fonction; ?>"/> <i class="px10">(Description de ce qu'il fait)</i></td>
                </tr>
                <?php show_bbcode_box_admin('description_edited'); ?>
                <tr>
                    <td>Description :</td><td><textarea name="description_edited" id="description_edited" cols="40" rows="4"><?php echo $description; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id_edited" value="<?php echo $id; ?>" /></td><td><input type="submit" name="save_edit_team" value="&Eacute;diter" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function show_tab_cmd() {
    require('./connexion.php');
//Selection de la table
    $query = "SELECT * FROM " . $database . "." . $tb_cmd . " ORDER BY id_cmd asc";
//Affichage de la selection
    $result = @mysql_query($query) OR DIE("Erreur de la s&eacute;lection des commandes : " . mysql_error());

    if (mysql_num_rows($result) == 0) {
        ?>
        <div id="box" onclick="document.getElementById('box').style.display='none';" class="info-box rounded" title="Fermer la fen&ecirc;tre">
            Aucune commande n'a encore &eacute;t&eacute; r&eacute;dig&eacute;e.
        </div>
        <br />
        <br />
        <?php
        add_cmd();
    } else {
        echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" id=\"pattern-style-b\" summary=\"Toutes les commandes\">";
        echo "<thead><th scope=\"col\">Commande</th><th scope=\"col\">Description</th><th scope=\"col\" colspan=\"2\"><form method=\"post\" //action=\"" . $_SERVER['PHP_SELF'] . "\">
            <input type=\"submit\" name=\"add\" value=\"Ajouter une commande\" class=\"btn\"></form></th></thead>";
        while ($cmd = mysql_fetch_assoc($result)) {
            echo "<tbody>";
            echo "<tr align=\"center\"><td>";
            echo $cmd['commande_cmd'] . "</td><td>";
            echo $cmd['description_cmd'];
            echo "</td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"edit_id\" value=\"" . $cmd ['id_cmd'] . "\"><input type='image' src=\"../images/icone/edit_little.png\" name='edit_faq' value='&Eacute;diter' alt='&Eacute;diter' title='&Eacute;diter'><br /></form></td><td>";
            echo "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\" ><input type=\"hidden\" name=\"del_id\" value=\"" . $cmd ['id_cmd'] . "\"><input type='image' src=\"../images/icone/delete_little.png\" name='del_faq' value='Supprimer' alt='Supprimer' title='Supprimer'><br /></form>";
            echo "</td></tr></tbody>";
        }
        echo "</table>";
    }
}

function add_cmd() {
    require('./connexion.php');
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellspacing="2" id="pattern-style-b" summary="Ajouter une question">
            <thead>
            <th colspan="2">Ajouter une commande</th>
            </thead>
            <tbody>
                <tr>
                    <td>Commande :</td><td><input type="text" name="commande" /></td>
                </tr>
                <?php show_bbcode_box_admin('description'); ?>
                <tr>
                    <td>Description :</td><td><textarea cols="50" rows="10" name="description" id="description"></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="save_cmd" value="Poster" class="btn" /></form></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}

function edit_cmd() {
    require('./connexion.php');
    $id = $_POST['edit_id'];
    $query = "SELECT * FROM " . $database . "." . $tb_cmd . " WHERE id_cmd = '$id'";
    $result = mysql_query($query) OR DIE(mysql_error());
    $modif = mysql_fetch_assoc($result);
    $commande = $modif['commande_cmd'];
    $description = $modif['description_cmd'];
    ?>
    <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
        <table cellpadding="2" cellspacing="2" id="pattern-style-b" summary="Editer une question">
            <thead>
            <th colspan="2">Editer une commande</th>
            </thead>
            <tbody>
                <tr>
                    <td>Commande :</td><td><input type="text" name="commande_edited" value="<?php echo $commande; ?>" /></td>
                </tr>
                <?php show_bbcode_box_admin('description_edited'); ?>
                <tr>
                    <td>Description :</td><td><textarea name="description_edited" id="description_edited" cols="50" rows="15"><?php echo $description; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr>
                    <td><input type="hidden" name="id_edited" value="<?php echo $id; ?>" /></td><td><input type="submit" name="save_edit_cmd" value="&Eacute;diter" class="btn" /></td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php
}
?>